package com.zjw.zy.service.helper;

import android.util.Log;

import com.zjw.zy.bean.Tip;
import com.zjw.zy.datasource.database.AppDataBase;
import com.zjw.zy.utils.AppUtils;
import com.zjw.zy.utils.NotificationUtils;
import com.zjw.zy.utils.TimeUtils;
import com.zjw.zy.utils.taskpool.TaskPool;

import java.util.List;

/**
 * @author ：zhong.jw
 * @date ：Created in 2022/11/3 11:51
 */
public final class TipsHelper {

    private static final String TAG = "TipsHelper";

    public static void init() {
        Log.d(TAG, "init() called");
        TaskPool.concurrent().post(() -> {
            List<Tip> all = AppDataBase.getInstance().tipsDao().queryAllByDone(false);

            for (Tip tip : all) {
                TimeUtils.TimeBean timeBean = TimeUtils.getTimeBean(tip.time);
                TimeUtils.addDayScheduler(timeBean, () -> {
                    NotificationUtils.sendTipNotification(AppUtils.getApp(), tip);
                });
            }

        });
    }

    public static void addSchedulerForTips(Tip tip) {
        Log.d(TAG, "addSchedulerForTips() called with: tip = [" + tip + "]");
        TaskPool.concurrent().post(() -> {
            TimeUtils.addDayScheduler(TimeUtils.getTimeBean(tip.time), () -> {
                NotificationUtils.sendTipNotification(AppUtils.getApp(), tip);
            });
        });
    }
}
